package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mysql.jdbc.Statement;

import model.Course;
import util.ConnectionUtil;

public class CourseDao {

	public static ArrayList<Course> queryCourseLise() {
		ArrayList<Course> courseList = new ArrayList<>();

		Connection conn = ConnectionUtil.getConnection();
		String sql = "SELECT * FROM course";

		try {
			Statement stat = (Statement) conn.createStatement();
			ResultSet rs = stat.executeQuery(sql);

			while (rs.next()) {
				String course_id = rs.getString(1);
				String course_name = rs.getString(2);
				String course_teacher = rs.getString(3);

				Course course = new Course(course_id, course_name, course_teacher);
				courseList.add(course);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return courseList;
	}

}
